package com.linln.modules.userule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linln.common.vo.PageResult;
import com.linln.modules.userule.domain.VehicleScanDO;
import com.linln.modules.userule.repository.VehicleScanMapper;
import com.linln.modules.userule.service.VehicleScanService;
import org.apache.logging.log4j.util.Strings;
import org.hibernate.sql.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;




@Service
public class VehicleScanServiceImpl extends ServiceImpl<VehicleScanMapper, VehicleScanDO> implements VehicleScanService {
	@Autowired
	VehicleScanMapper vehicleScanMapper;

	@Override
	public PageResult<VehicleScanDO> getVehicleScanList(Integer pageNum, Integer limit, String plate) {
		PageHelper.startPage(pageNum, limit);
		QueryWrapper<VehicleScanDO> queryWrapper = null;
		if (!Strings.isBlank(plate)) {
			queryWrapper = new QueryWrapper<VehicleScanDO>().like("use_rule_name", plate);
		}
		PageInfo<VehicleScanDO> pageInfo = new PageInfo<>(this.list(queryWrapper));
		PageResult<VehicleScanDO> pageResult = new PageResult<>();
		pageResult.setData(pageInfo.getList());
		pageResult.setCount(pageInfo.getTotal());
		return pageResult;
	}

	@Override
	public boolean delVehicleScan(String vehicleScanId) {
		return false;
	}

	@Override
	public boolean saveVehicleScan(VehicleScanDO vehicleScanDO) {
		if(vehicleScanMapper.insert(vehicleScanDO) > 0){
			return true;
		}
		return false;
	}

	@Override
	public VehicleScanDO getVehicleScan(String plate) {
		return vehicleScanMapper.selectOne(new QueryWrapper<VehicleScanDO>().select("plate",plate));
	}
}
